/****************************************************************************
 *
 * This file is part of the CodeMax editor support code.
 *
 * Primary author: Christopher J. Cason.
 *
 * from Persistence of Vision(tm) Ray Tracer version 3.6.
 * Copyright 1991-2003 Persistence of Vision Team
 * Copyright 2003-2004 Persistence of Vision Raytracer Pty. Ltd.
 *---------------------------------------------------------------------------
 * NOTICE: This source code file is provided so that users may experiment
 * with enhancements to POV-Ray and to port the software to platforms other
 * than those supported by the POV-Ray developers. There are strict rules
 * regarding how you are permitted to use this file. These rules are contained
 * in the distribution and derivative versions licenses which should have been
 * provided with this file.
 *
 * These licences may be found online, linked from the end-user license
 * agreement that is located at http://www.povray.org/povlegal.html
 *---------------------------------------------------------------------------
 * This program is based on the popular DKB raytracer version 2.12.
 * DKBTrace was originally written by David K. Buck.
 * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
 *---------------------------------------------------------------------------
 * Thanks to WinMain Software (http://www.winmain.com/) for providing the (at
 * the time commercial) CodeMax edit control which the POVWIN editor is based.
 *---------------------------------------------------------------------------
 * $File: //depot/misc/win-sourcedist/codemax/EditForm.h $
 * $Revision: #1 $
 * $Change: 2944 $
 * $DateTime: 2004/07/05 13:11:12 $
 * $Author: chrisc $
 * $Log$
 *****************************************************************************/

#ifndef EditFormH
#define EditFormH
//---------------------------------------------------------------------------
#include <registry.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include "TCodeMax.h"
#include <Menus.hpp>
#include <Dialogs.hpp>
#include "cdiroutl.h"
#include <Grids.hpp>
#include <Outline.hpp>
#include "CTabControl.h"

//---------------------------------------------------------------------------
typedef struct
{
  FILETIME              TimeSaved ;
  AnsiString            ShortName ;
  AnsiString            LongName ;
} EditTagStruct ;

//---------------------------------------------------------------------------
class TRegDef : public TRegistry
{
  public:
    TRegDef (AnsiString Path) ;
    int ReadInt (AnsiString Name, int defval) ;
    bool ReadBool (AnsiString Name, bool defval) ;
    int ReadBin (AnsiString Name, char *data, int len, char *defval) ;
    int ReadBin (AnsiString Name, char **data, int len, char *defval) ;
    AnsiString ReadString (AnsiString Name, AnsiString defval) ;
} ;

//---------------------------------------------------------------------------
class TImageHintWindow : public TCustomControl
{
  public:
    __fastcall TImageHintWindow (HANDLE Parent, tagRECT &rect, Graphics::TBitmap *bmp) ;
    __fastcall virtual ~TImageHintWindow () ;
    bool __fastcall IsHintMessage (int Message) ;
    virtual void __fastcall CreateParams (TCreateParams &Params) ;

  private:
    Graphics::TBitmap *bitmap ;
    virtual void __fastcall Paint (void) ;
} ;

//---------------------------------------------------------------------------
class TParentForm : public TForm
{
  __published:
    TPopupMenu *PopupMenu;
    TMenuItem *pmiContextHelp;
    TMenuItem *pmiOpenFile;
    TMenuItem *pmiCloseFile;
    TMenuItem *pmiShowMessages;
    TPopupMenu *Menus;
    TMenuItem *miFileMenu;
    TMenuItem *miNewFile;
    TMenuItem *miOpenFile;
    TMenuItem *N13;
    TMenuItem *miCloseFile;
    TMenuItem *miCloseAllFiles;
    TMenuItem *N14;
    TMenuItem *miSave;
    TMenuItem *miSaveAs;
    TMenuItem *miSaveAll;
    TMenuItem *N2;
    TMenuItem *miPrint;
    TMenuItem *miPrintSetup;
    TMenuItem *miExit;
    TMenuItem *FileBreak;
    TMenuItem *miEditMenu;
    TMenuItem *miUndo;
    TMenuItem *N6;
    TMenuItem *miCut;
    TMenuItem *miCopy;
    TMenuItem *miPaste;
    TMenuItem *miSearchMenu;
    TMenuItem *miFind;
    TMenuItem *miReplace;
    TMenuItem *miFindNext;
    TMenuItem *N3;
    TMenuItem *miGoToLine;
    TMenuItem *miEditorMenu;
    TMenuItem *miCreateBackups;
    TPrintDialog *PrintDialog;
    TMenuItem *pmiCut;
    TMenuItem *pmiCopy;
    TMenuItem *pmiPaste;
    TMenuItem *pmiUndo;
    TMenuItem *pmiRedo;
    TMenuItem *N01;
    TMenuItem *N11;
    TMenuItem *miRedo;
    TMenuItem *N5;
    TMenuItem *miProperties;
    TMenuItem *pmiProperties;
    TTimer *EditDragPanelTimer;
    TMenuItem *miUndoAfterSave;
    TMenuItem *miInsertMenu;
    TMenuItem *miEditInsertMenu;
    TMenuItem *miAutoReload;
    TMenuItem *miAutoReloadNever;
    TMenuItem *miAutoReloadAsk;
    TMenuItem *miAutoReloadAlways;
    TMenuItem *N1;
    TMenuItem *N7;
    TPanel *EditDragPanel;
    TPanel *HiddenPanel;
    TMenuItem *N8;
    TMenuItem *miOlderFiles;
    TMenuItem *miShowParseMessages;
    TMenuItem *miAutoLoadErrorFile;
    TMenuItem *N9;
    TMenuItem *miSelectAll;
    TMenuItem *miTextMenu;
    TMenuItem *miBookmarks;
    TMenuItem *miClearAllBookmarks;
    TMenuItem *miFirstBookmark;
    TMenuItem *miLastBookmark;
    TMenuItem *miNextBookmark;
    TMenuItem *miPreviousBookmark;
    TMenuItem *miToggleBookmark;
    TMenuItem *miDelete;
    TMenuItem *miMatchBrace;
    TMenuItem *miPlayMacro;
    TMenuItem *miPlayMacro1;
    TMenuItem *miPlayMacro2;
    TMenuItem *miPlayMacro9;
    TMenuItem *miPlayMacro8;
    TMenuItem *miPlayMacro7;
    TMenuItem *miPlayMacro6;
    TMenuItem *miPlayMacro5;
    TMenuItem *miPlayMacro4;
    TMenuItem *miPlayMacro3;
    TMenuItem *miPlayMacro10;
    TMenuItem *miRecordMacro;
    TMenuItem *miSetRepeatCount;
    TMenuItem *N10;
    TMenuItem *miShowWhiteSpace;
    TMenuItem *N12;
    TMenuItem *miIndentStyle;
    TMenuItem *miIndentStyleCopy;
    TMenuItem *miIndentStyleLanguage;
    TMenuItem *miIndentStyleNone;
    TMenuItem *miSelection;
    TMenuItem *miTabsToSpaces;
    TMenuItem *miSpacesToTabs;
    TMenuItem *miLowercaseSelection;
    TMenuItem *miUppercaseSelection;
    TMenuItem *miUndentSelection;
    TMenuItem *miIndentSelectionPrevious;
    TMenuItem *miIndentSelection;
    TMenuItem *N16;
    TMenuItem *miSetTabSize;
    TMenuItem *miScrollBars;
    TMenuItem *miScrollNone;
    TMenuItem *miScrollHorizontal;
    TMenuItem *miScrollVertical;
    TMenuItem *miScrollBoth;
    TTimer *AutoSaveTimer;
    TMenuItem *miAutoSave;
    TMenuItem *miShowMessages;
    TMenuItem *miColourScheme;
    TMenuItem *miCustomColours;
    TMenuItem *miBlackOnWhite;
    TMenuItem *miWhiteOnBlack;
    TMenuItem *pmiOpenFileUnderCursor;
    TPanel *MessagePanel;
    TTabControl *Tab;
    TMenuItem *miExtraIndent;
    TMenuItem *miExtraIndentSelection;
    TMenuItem *miExtraUndentSelection;
    TMenuItem *miExtraIndentSelectionPrevious;
    TMenuItem *pmiSelection;
    TMenuItem *pmiTabsToSpaces;
    TMenuItem *pmiSpacesToTabs;
    TMenuItem *pmiLowercaseSelection;
    TMenuItem *pmiUppercaseSelection;
    TMenuItem *pmiUndentSelection;
    TMenuItem *pmiIndentSelectionPrevious;
    TMenuItem *pmiIndentSelection;
    TMenuItem *N17;
    TMenuItem *pmiSearch;
    TMenuItem *pmiGoToLine;
    TMenuItem *pmiMatchBrace;
    TMenuItem *N18;
    TMenuItem *pmiFindNext;
    TMenuItem *pmiReplace;
    TMenuItem *pmiFile;
    TMenuItem *pmiSave;
    TMenuItem *pmiSaveAs;
    TMenuItem *pmiSaveAll;
    TMenuItem *pmiBookmark;
    TMenuItem *pmiToggleBookmark;
    TMenuItem *pmiPreviousBookmark;
    TMenuItem *pmiNextBookmark;
    TMenuItem *pmiLastBookmark;
    TMenuItem *pmiFirstBookmark;
    TMenuItem *pmiClearAllBookmarks;
    TMenuItem *pmiFind;
    TMenuItem *pmiPrint;
    TMenuItem *pmiCloseCurrentFile;
    TMenuItem *miCursorBeyondEOL;
    TMenuItem *miConstrainCaret;
    TMenuItem *N4;
    TMenuItem *N15;
    TMenuItem *miOverlayKeywordExpansion;
    TMenuItem *miFileMenuHelp;
    TMenuItem *miFileMenuHelpSeparator;
    TMenuItem *miEditMenuHelp;
    TMenuItem *miEditMenuHelpSeparator;
    TMenuItem *miSearchMenuHelp;
    TMenuItem *miSearchMenuHelpSeparator;
    TMenuItem *miTextMenuHelp;
    TMenuItem *miTextMenuHelpSeparator;
    TMenuItem *miEditorMenuHelp;
    TMenuItem *miEditorMenuHelpSeparator;
    TMenuItem *miInsertMenuHelp;
    TMenuItem *N24;

    void __fastcall MessagePanelResize(TObject *Sender);
    void __fastcall TabChange(TObject *Sender);
    
    
    
    void __fastcall miNewFileClick(TObject *Sender);
    void __fastcall miOpenFileClick(TObject *Sender);
    void __fastcall miCloseFileClick(TObject *Sender);
    void __fastcall miCloseAllFilesClick(TObject *Sender);
    void __fastcall miPrintClick(TObject *Sender);
    
    void __fastcall miExitClick(TObject *Sender);
    void __fastcall miPrintSetupClick(TObject *Sender);
    
    void __fastcall miSaveAllClick(TObject *Sender);
    void __fastcall miSaveClick(TObject *Sender);
    void __fastcall miSaveAsClick(TObject *Sender);
    void __fastcall miUndoAfterSaveClick(TObject *Sender);
    void __fastcall miPropertiesClick(TObject *Sender);

    
    void __fastcall miUndoClick(TObject *Sender);
    void __fastcall miRedoClick(TObject *Sender);
    void __fastcall miCutClick(TObject *Sender);
    void __fastcall miCopyClick(TObject *Sender);
    void __fastcall miPasteClick(TObject *Sender);
    void __fastcall MenusPopup(TObject *Sender);
    void __fastcall FormCreate(TObject *Sender);
    void __fastcall miFindClick(TObject *Sender);
    void __fastcall miReplaceClick(TObject *Sender);
    void __fastcall miFindNextClick(TObject *Sender);
    void __fastcall miGoToLineClick(TObject *Sender);
    
    void __fastcall pmiContextHelpClick(TObject *Sender);
    
    void __fastcall miEditInsertMenuClick(TObject *Sender);
    
    void __fastcall EditDragPanelMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
    void __fastcall FormResize(TObject *Sender);
    void __fastcall EditDragPanelMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
    void __fastcall EditDragPanelMouseMove(TObject *Sender, TShiftState Shift,
          int X, int Y);
    void __fastcall pmiShowMessagesClick(TObject *Sender);
    void __fastcall EditDragPanelTimerTimer(TObject *Sender);
    void __fastcall miShowParseMessagesClick(TObject *Sender);
    void __fastcall miAutoLoadErrorFileClick(TObject *Sender);
    void __fastcall miSelectAllClick(TObject *Sender);
    void __fastcall miDeleteClick(TObject *Sender);
    void __fastcall miIndentSelectionClick(TObject *Sender);
    void __fastcall miUndentSelectionClick(TObject *Sender);
    void __fastcall miIndentSelectionPreviousClick(TObject *Sender);
    void __fastcall miUppercaseSelectionClick(TObject *Sender);
    void __fastcall miLowercaseSelectionClick(TObject *Sender);
    void __fastcall miSpacesToTabsClick(TObject *Sender);
    void __fastcall miTabsToSpacesClick(TObject *Sender);
    void __fastcall miMatchBraceClick(TObject *Sender);
    void __fastcall miSetRepeatCountClick(TObject *Sender);
    void __fastcall miRecordMacroClick(TObject *Sender);
    void __fastcall miPlayMacroClick(TObject *Sender);
    void __fastcall miClearAllBookmarksClick(TObject *Sender);
    void __fastcall miFirstBookmarkClick(TObject *Sender);
    void __fastcall miLastBookmarkClick(TObject *Sender);
    void __fastcall miNextBookmarkClick(TObject *Sender);
    void __fastcall miPreviousBookmarkClick(TObject *Sender);
    void __fastcall miToggleBookmarkClick(TObject *Sender);
    void __fastcall miShowWhiteSpaceClick(TObject *Sender);
    void __fastcall miIndentStyleClick(TObject *Sender);
    void __fastcall miSetTabSizeClick(TObject *Sender);
    void __fastcall miScrollBarsClick(TObject *Sender);
    void __fastcall miCreateBackupsClick(TObject *Sender);
    void __fastcall miAutoSaveClick(TObject *Sender);
    void __fastcall AutoSaveTimerTimer(TObject *Sender);
    void __fastcall miBlackOnWhiteClick(TObject *Sender);
    void __fastcall miWhiteOnBlackClick(TObject *Sender);
    void __fastcall pmiOpenFileUnderCursorClick(TObject *Sender);
    void __fastcall PopupMenuPopup(TObject *Sender);
    void __fastcall miAutoReloadAlwaysClick(TObject *Sender);
    void __fastcall miCursorBeyondEOLClick(TObject *Sender);
    void __fastcall miConstrainCaretClick(TObject *Sender);
    void __fastcall miOverlayKeywordExpansionClick(TObject *Sender);
    void __fastcall miFileMenuHelpClick(TObject *Sender);
    void __fastcall miEditMenuHelpClick(TObject *Sender);
    void __fastcall miSearchMenuHelpClick(TObject *Sender);
    void __fastcall miTextMenuHelpClick(TObject *Sender);
    void __fastcall miEditorMenuHelpClick(TObject *Sender);
    void __fastcall miInsertMenuHelpClick(TObject *Sender);
    void __fastcall pmiCopyCommandLineClick(TObject *Sender) ;
        
        
        void __fastcall FormDestroy(TObject *Sender);
  private:
    virtual void __fastcall CreateParams (TCreateParams &Params) ;
    bool KeywordExpansion (TCodeMax *Editor, bool Reverse, bool OverlayCommand) ;
    HWND CodeListWindow ;
    bool IgnoreNext ;
    AnsiString ExpansionWord ;
    int ExpansionAnchorCol ;
    int ExpansionAnchorLine ;
    int ExpansionIndex ;
    int ExpansionLastCol ;
    bool ExpansionHasCompleteMatch ;

  public:
    __fastcall TParentForm(TComponent* Owner);
    TCodeMax *CreateNewEditor (char *FileName, bool ReadOnly = false, bool ShowIt = true) ;
    bool CanClose (bool AllFiles) ;
    void __fastcall EditParentWndProc (Messages::TMessage& Message) ;
    void __fastcall CodeMaxKeyUp(TObject *Sender, WORD &Key, TShiftState Shift) ;
    void SetMenuState (void) ;
    void __fastcall RecentMenuClick (TObject *Sender) ;
    void __fastcall TabWndProc (Messages::TMessage& Message) ;
    void __fastcall InsertMenuClick (TObject *Sender) ;
    void ShowEditDragPanel (bool Showing) ;
    void GetSettings (TRegDef *t, bool RestoreFiles) ;
    void PutSettings (TRegDef *t) ;
    void __fastcall OlderMenuClick (TObject *Sender) ;
    void __fastcall CodeMaxKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) ;
    void SetMenuShortcut (TMenuItem *m, WORD Command) ;
    void SetMenuShortcut (TMenuItem *m1, TMenuItem *m2, WORD Command) ;
    HWND Initialise (void) ;
    void SetMenuShortcuts (void) ;
    void __fastcall OnHint (TObject* Sender) ;
    AnsiString LocateIncludeFilename (int line, int col, TCodeMax *e) ;
    AnsiString LocateCommandLine (int line, TCodeMax *e) ;

    //---------------------------------------------------------------------------
};
//---------------------------------------------------------------------------
extern PACKAGE TParentForm *ParentForm;
//---------------------------------------------------------------------------
#endif
